1 /**************************************************************************
2 Copyright 2005 Webstersmalley
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 *************************************************************************/
16
17
18
19 package com.webstersmalley.statuslog;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23 import org.apache.log4j.AppenderSkeleton;
24 import org.apache.log4j.spi.LoggingEvent;
25
26 /***
27 * @author Matthew Smalley
28 */
29 public class StatusAppender extends AppenderSkeleton
30 {
31 private StatusFrame statusFrame;
32
33 public StatusAppender()
34 {
35 }
36
37 protected synchronized void getStatusFrame()
38 {
39 if (statusFrame == null)
40 {
41 statusFrame = new StatusFrame();
42 }
43 }
44
45
46
47
48 protected void append(LoggingEvent le)
49 {
50 getStatusFrame();
51 statusFrame.addLoggingEntry(le);
52 }
53
54
55
56
57 public boolean requiresLayout()
58 {
59 return false;
60 }
61
62
63
64
65 public void close()
66 {
67 }
68
69 public static void main(String[] args)
70 {
71 Log log = LogFactory.getLog(StatusAppender.class);
72 while (true)
73 {
74 log.info("hello!");
75 StatusLog.info("Hello2!");
76 try
77 {
78 Thread.sleep(500);
79 } catch (InterruptedException e)
80 {
81
82 e.printStackTrace();
83 }
84 }
85 }
86 }